﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using _MetalSlug.Form.ScreenSystem;
using _MetalSlug.Form.ScreenSystem.Message;

namespace _MetalSlug.Form.OptionScreen
{
    public class OptionScreen : MyScreen
    {
        SpriteFont fontCharacter;
        public SpriteFont FontCharacter
        {
            get { return fontCharacter; }
            set { fontCharacter = value; }
        }

        Color fontColorDefault;
        public Color FontColorDefault
        {
            get { return fontColorDefault; }
            set { fontColorDefault = value; }
        }

        Color fontColorChosen;
        public Color FontColorChosen
        {
            get { return fontColorChosen; }
            set { fontColorChosen = value; }
        }

        List<SettingDisplayer> lstSettingObjects;
        int indexSetting;

        public int IndexSetting
        {
            get { return indexSetting; }
            set 
            { 
                indexSetting = value;
                if(lstSettingObjects != null)
                {
                    lstSettingObjects[value].IsSetting = true; 
                }   
            }
        }

        public OptionScreen(SpriteFont currentFont)
        {  
            LoadContent();
            InitialAttribute();
            FontCharacter = currentFont;
        }

        public override void LoadContent()
        {
            lstSettingObjects = new List<SettingDisplayer>();          
            AudioSettingDisplayer AudioSettingObject = new AudioSettingDisplayer();
            lstSettingObjects.Add(AudioSettingObject);
            DifficultySettingDisplayer DifficultySettingObject = new DifficultySettingDisplayer();
            lstSettingObjects.Add(DifficultySettingObject);
            Background = GameUtil.LoadTexture("setting");
        }

        public override void Update(GameTime gameTime)
        {
            lstSettingObjects[IndexSetting].Update(gameTime);
            HandleKeyboard();
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            foreach (SettingDisplayer settingObject in lstSettingObjects)
            {
                settingObject.Draw(spriteBatch,FontCharacter,FontColorDefault,FontColorChosen);
            }
        }

        public override void HandleKeyboard()
        {
            if (UserInput.isKeyClicked(Keys.Up))
            {
                IndexSetting = (IndexSetting - 1 + lstSettingObjects.Count) % lstSettingObjects.Count;
            }

            if (UserInput.isKeyClicked(Keys.Down))
            {
                IndexSetting = (IndexSetting + 1) % lstSettingObjects.Count;
            }

            if (UserInput.isKeyClicked(Keys.Escape))
            {
                this.Send(TYPE.MAINMENU, MyMessage.TYPE.SHOW, null);
            }
        }

        public override void InitialAttribute()
        {
            TypeOfWindow = TYPE.SETTING;
            FontColorDefault = Color.Violet;
            FontColorChosen = Color.YellowGreen;
            IndexSetting = 0;
        }
    }
}
